import type { ConsultType } from '@/enum'
import type { PartialConsultInfo } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useConsultStore = defineStore(
  'consult',
  () => {
    // 患者的就诊状态信息集合
    const consultInfo = ref<PartialConsultInfo>({})
    // 修改患者就诊信息
    // 1. 修改就诊类型
    const setType = (type: ConsultType) => {
      consultInfo.value.type = type
    }
    // 2. 修改问诊类型
    const setIllnessType = (type: 0 | 1) => {
      consultInfo.value.illnessType = type
    }
    // 3. 修改科室信息
    const setDepInfo = (depId: string) => {
      consultInfo.value.depId = depId
    }
    // 4. 修改症状描述
    const setIllnessDesc = (desc: PartialConsultInfo) => {
      consultInfo.value.illnessDesc = desc.illnessDesc
      consultInfo.value.illnessTime = desc.illnessTime
      consultInfo.value.consultFlag = desc.consultFlag
      consultInfo.value.pictures = desc?.pictures || []
    }
    // 5. 修改患者信息
    const setPatientInfo = (patientId: string) => {
      consultInfo.value.patientId = patientId
    }
    // 6. 修改优惠券信息
    const setCouponId = (couponId: string) => {
      consultInfo.value.couponId = couponId
    }
    // 7. 清空问诊信息
    const clearConsultInfo = () => {
      consultInfo.value = {}
    }
    // 问诊室id
    const routeConfig = ref({})
    const updateRoomConfig = (obj: object) => {
      routeConfig.value = obj
    }
    return {
      consultInfo,
      setCouponId,
      setPatientInfo,
      setIllnessDesc,
      setDepInfo,
      setIllnessType,
      setType,
      clearConsultInfo,
      routeConfig,
      updateRoomConfig
    }
  },
  {
    persist: true
  }
)
